package com.qf.java2201.web;

import com.qf.java2201.pojo.HComment;
import com.qf.java2201.pojo.HUserinfo;
import com.qf.java2201.service.CommentService;
import com.qf.java2201.service.UserInfoService;
import com.qf.java2201.service.impl.CommentServiceImpl;
import com.qf.java2201.service.impl.UserInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @date 2022/4/8
 * @desc   预约详情  展示医生详情 和 预约日期  时间段 和 评论
 */
@WebServlet("/showXq")
public class ShowXqServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //TODO 查询预约的医生的详情
        String did = req.getParameter("did");

        UserInfoService userInfoService = new UserInfoServiceImpl();

        //根据主键 查询用户详情  did
        HUserinfo  userinfo =userInfoService.findUserInfoBydid(did);

        //req.setAttribute("doc",userinfo);
        HttpSession session = req.getSession();
        session.setAttribute("doc",userinfo);

        // 准备 评论的数据

        CommentService commentService = new CommentServiceImpl();

        //根据 医生 did 查询之前的用户对该医生的评论
        List<HComment>  comments = commentService.findCommentByDid(did);

        req.setAttribute("cs",comments);

        //跳转到 xq.jsp
        req.getRequestDispatcher("/xq.jsp").forward(req,resp);
    }
}
